<?php
if (!$filter_on) { ?>
<script type="text/javascript">
function openFilter() {
	$('#filter_button').hide();
	$('#filter').show();
	return false;
}
</script>
<?php } ?>

<table cellspacing="0" cellpadding="0" style="width:100%;">
	<tr>
		<td style="width:250px; padding-<?php echo Config::get('align_not', 'i18n')?>:10px;">
			<?php
			foreach ($cat_list as $category) {
				$class_name = 'simple_tree_off';
				if ($cat_id == intval($category['id'])) {
					$class_name = 'simple_tree_on';
				} ?>
				<a href="<?php echo CURRENT_URL, $category['id']; ?>" class="<?php echo $class_name; ?>" style="margin-<?php echo Config::get('align', 'i18n')?>:<?php echo ($category['level'] * 5); ?>px;">
					<div class="simple_tree_item_off" cat_id="<?php echo $category['id']; ?>">
						<?php echo $category['name']; ?>
					</div>
				</a>
			<?php } ?>
		</td>
		<td>
			<div>
			<?php if (!$filter_on) { ?>
				<div id="filter_button" style="margin-bottom:10px;"><a href="#" onclick="return openFilter();">Filter</a></div>
			<?php } ?>
				<div id="filter" style="<?php if (!$filter_on) { ?>display:none; <?php } ?>margin-bottom:10px; padding:10px; background:#f7f7f7; border:1px solid #ddd;">
					<form action="<?php echo CURRENT_URL, $cat_id, '/1/'; ?>" method="get">
						<table cellspacing="0" cellpadding="0" style="width:100%;">
							<colgroup>
								<col width="33%" />
								<col width="33%" />
								<col width="33%" />
							</colgroup>
							<tr>
								<td>
									<div>Id</div>
									<div><input type="text" name="doc_id" value="<?php if (isset($options['id'])) { echo $options['id']; } ?>" /></div>
								</td>
								<td>
									<div>Name</div>
									<div><input type="text" name="doc_name" value="<?php if (isset($options['name'])) { echo $options['name']; } ?>" /></div>
								</td>
								<td>
									<div>Alias</div>
									<div><input type="text" name="doc_alias" value="<?php if (isset($options['alias'])) { echo $options['alias']; } ?>" /></div>
								</td>
							</tr>
							<tr>
								<td>
									<div>Status</div>
									<div>
										<?php
										$schemas = Schema::getList(1);
										?>
										<select name="doc_status">
											<option value="0">-- Select status --</option>
											<option value="1"<?php if (isset($options['status_id']) && (1 == intval($options['status_id']))) { echo ' selected="selected"'; } ?>><?php echo __('Opened'); ?></option>
											<option value="2"<?php if (isset($options['status_id']) && (2 == intval($options['status_id']))) { echo ' selected="selected"'; } ?>><?php echo __('Closed'); ?></option>
										</select>
									</div>
								</td>
								<td>
									<div>Schema</div>
									<div>
										<?php
										$schemas = Schema::getList(1);
										?>
										<select name="doc_schema">
											<option value="0">-- Select schema --</option>
										<?php foreach ($schemas as $schema) { ?>
											<option value="<?php echo $schema['id']; ?>"<?php if (isset($options['schema_id']) && (intval($schema['id']) == intval($options['schema_id']))) { echo ' selected="selected"'; } ?>><?php echo $schema['name']; ?></option>
										<?php } ?>
										</select>
									</div>
								</td>
								<td>
									<div style="padding:20px 0px 0px 0px;">
										<table border="0" cellpadding="0" cellspacing="0" style="width:100%;">
											<tr>
												<td class="reverse_text" style="vertical-align:middle; padding:0px 10px;"><a href="<?php echo CURRENT_URL, $cat_id, '/1'; ?>">Cancel</a></td>
												<td style="width:150px;"><input type="submit" value="Search" style="width:100%;" class="btn btn-primary" /></td>
											</tr>
										</table>
									</div>
								</td>
							</tr>
						</table>
					</form>
				</div>
			</div>
			<?php if (count($doc_list) > 0) { ?>
				<div>
					<?php
					$cnt = 0;
					foreach ($doc_list as $document) {
						$status_title = '-';
						$status_color = '#000';
						$class_name = ' list_item_opened';
						if (1 == intval($document['status_id'])) {
							$status_title = __('Opened');
						} else if (2 == intval($document['status_id'])) {
							$status_title = __('Closed');
							$status_color = '#777';
							$class_name = ' list_item_closed';
						}
						
						$schema_title = Schema::getTitle($document['schema_id']);	?>
						<div id="list-<?php echo $document['id']; ?>" class="list_item_list_block">
							<div class="list_item<?php echo $class_name; ?>" style="cursor:pointer;" onclick="Core.List.openInfo(<?php echo $document['id']; ?>)">
								<div style="color:<?php echo $status_color; ?>;">
									<?php echo $document['name'];
									if (!empty($document['alias'])) { ?>
										(<?php echo $document['alias']; ?>)
									<?php } ?>
									<span class="label pull-right"><?php echo $schema_title; ?><span>
								</div>
							</div>
						</div>
						<div id="info-<?php echo $document['id']; ?>" class="list_item_info_block">
							<div class="list_item_active" style="cursor:pointer;" onclick="Core.List.closeInfo()">
								<div style="color:<?php echo $status_color; ?>;">
									<?php echo $document['name']; ?>
								</div>
							</div>
							<div style="padding:5px;">
								<div style="font-size:0.8em;">
									<b style="color:#2b6fb6;"><?php echo __('Id'); ?>:</b> <?php echo $document['id']; ?>
									&nbsp;
									<b style="color:#2b6fb6;"><?php echo __('Status'); ?>:</b> <?php echo $status_title; ?>
									&nbsp;
									<b style="color:#2b6fb6;"><?php echo __('Schema'); ?>:</b> <?php echo $schema_title; ?>
								<?php if (!empty($document['alias'])) { ?>
									&nbsp;
									<b style="color:#2b6fb6;"><?php echo __('Alias'); ?>:</b> <?php echo $document['alias']; ?>
								<?php } ?>
								</div>
							</div>
							<div class="list_item_links">
								<a href="<?php echo BASE_URL; ?>document/update/<?php echo $document['id']; ?>" class="list_link"><?php echo __('Edit'); ?></a>
								&nbsp;
								<a href="<?php echo BASE_URL; ?>document/categories/<?php echo $document['id']; ?>" class="list_link"><?php echo __('Categories'); ?></a>
								&nbsp;
								<a href="<?php echo BASE_URL; ?>document/sequence/<?php echo $document['id']; ?>/<?php echo $cat_id; ?>" class="list_link"><?php echo __('Sequence'); ?></a>
								&nbsp;
								<a href="<?php echo BASE_URL; ?>document/delete/<?php echo $document['id']; ?>/<?php echo $cat_id; ?>" class="list_link"><?php echo __('Delete'); ?></a>
							</div>
						</div>
						<?php
						$cnt++;
					} ?>
				</div>
				<div>
					<?php
					$paging = new Paging($count, $options['page_id'], $options['page_size'], (CURRENT_URL . $cat_id . '/{%page_id%}/' . $filter_url), 10);
					$paging->draw();
					?>
				</div>
			<?php } else {
				echo __('No documents found');
			} ?>
		</td>
	</tr>
</table>